package adapter;

import android.bluetooth.BluetoothDevice;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import base.BaseApplication;
import xm.chengdu.com.sbglxt.R;


/**
 * Created by 浠栫殑鐚� on 2016/12/3.
 * 閾惰鍗￠�傞厤鍣�
 */

public class MyAdapter extends Base_Z_Adapter {
    MyAdapter.Holder holder;

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        // 复用convertView
        if (null == convertView) {
            convertView = LayoutInflater.from(BaseApplication.getInstance())
                    .inflate(R.layout.tab_lv, null);
            holder = new MyAdapter.Holder();

            holder.name = (TextView) convertView
                    .findViewById(R.id.name);


            // 设置Holder
            convertView.setTag(holder);
        } else {
            holder = (MyAdapter.Holder) convertView.getTag();
        }
        BluetoothDevice bluetoothDevice = (BluetoothDevice) getItem(position);
        holder.name.setText(bluetoothDevice.getName() + "/n" + getState(bluetoothDevice.getBondState()));
        return convertView;
    }

    private String getState(int state) {
        switch (state) {
            case BluetoothDevice.BOND_NONE:
                return "未配对";
            case BluetoothDevice.BOND_BONDING:
                return "\n正在配对";
            case BluetoothDevice.BOND_BONDED:
                return "\n已配对";
            default:
                return "";
        }
    }

    public class Holder {

        TextView name;

    }
}
